package com.atguigu.day03;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
import org.apache.flink.util.Collector;

/**
 * @description :
 * @autor :lyh
 */
public class Example6 {
    public static void main(String[] args) throws Exception{
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        env
                .fromElements("white","black","gray")
                .keyBy(r -> "String")
                .process(new KeyedProcessFunction<String, String, String>() {
                    @Override
                    public void processElement(String in, KeyedProcessFunction<String, String, String>.Context ctx, Collector<String> out) throws Exception {
                        if (in.equals("white")) {
                            out.collect(in+"输入数据 in 的 key 是：" + ctx.getCurrentKey());
                        } else if (in.equals("black")) {
                            out.collect(in+"输入数据 in 的 key 是：" + ctx.getCurrentKey());
                            out.collect(in+"输入数据 in 的 key 是：" + ctx.getCurrentKey());
                        }
                    }
                })
                .print();

        env.execute();
    }
}
